package com.liudadan.controller;

import com.liudadan.pojo.User;
import jakarta.ws.rs.DELETE;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("user")
@RestController
public class UserController {
    /**
     * 查询用户列表
     *
     * @param page
     * @param size
     * @return
     */

    @GetMapping
    public List<User> findList(@RequestParam(defaultValue = "1", required = false) int page,
                               @RequestParam(defaultValue = "10", required = false) int size) {
        System.out.println("UserController.findlist");
        System.out.println("page:" + page + " size:" + size);

        List<User> list = new ArrayList<User>();
        User user = new User();
        user.setName("liudadan");
        user.setAge(18);
        list.add(user);
        return list;
    }

    /**
     * 根据id查询用户
     *
     * @param id
     * @return
     */
    @GetMapping("{id}")
    public User findUser(@PathVariable Integer id) {
        System.out.println("UserController.findUser");
        System.out.println("id:" + id);
        User user = new User();
        user.setId(id);
        user.setName("liudadan");
        user.setAge(18);
        return user;
    }

    /**
     * 保存用户
     *
     * @param user
     * @return
     */
    @PostMapping
    public User saveUser(@RequestBody User user) {
        System.out.println("UserController.saveUser");
        System.out.println("user:" + user);
        return user;
    }

    /**
     * 修改用户
     *
     * @param id
     * @param user
     * @return
     */
    @PutMapping("{id}")
    public User updateUser(@PathVariable Integer id, @RequestBody User user) {
        System.out.println("UserController.updateUser");
        System.out.println("id:" + id);
        System.out.println("user:" + user);
        return null;
    }

    /**
     * 删除用户
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    public User deleteUser(@PathVariable Integer id) {
        System.out.println("UserController.deleteUser");
        System.out.println("id:" + id);
        return null;
    }

    @GetMapping("search")
    public List<User> searchUser(String keyword,
                                 @RequestParam(defaultValue = "1", required = false) int page,
                                 @RequestParam(defaultValue = "10", required = false) int size) {
        System.out.println("UserController.searchUser");
        System.out.println("keyword:" + keyword+ " page:" + page + " size:" + size);
        return null;
    }
}
